import React, { Suspense } from "react";
import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
import routes from "./Router_Cfig";
type Props = {};

const Router_View = (props: Props) => {
  const renderRouts = (arr: any) => {
    return arr.map((item: any, index: any) => {
      return (
        <Route
          key={index}
          path={item.path}
          element={
            item.element ? (
              <item.element></item.element>
            ) : (
              <Navigate to={item.to}></Navigate>
            )
          }
        >
          {item.children && renderRouts(item.children)}
        </Route>
      );
    });
  };
  return (
    <Suspense fallback={<div>加载中...</div>}>
      <BrowserRouter>
        <Routes>{renderRouts(routes)}</Routes>
      </BrowserRouter>
    </Suspense>
  );
};

export default Router_View;
